package com.transcasafe.eanpay.example.pay;

import com.alibaba.fastjson.JSONObject;
import com.transcasafe.eanpay.core.config.EanPayConfig;
import com.transcasafe.eanpay.core.service.EanPayCardService;
import com.transcasafe.eanpay.core.service.model.CreateReadiesPaymentRequest;
import com.transcasafe.eanpay.core.service.model.PaymentsPayResponse;
import com.transcasafe.eanpay.core.util.NonceUtil;
import com.transcasafe.eanpay.example.MchConfig;

/**
 * Readies代收订单创建
 */
public class EanPayReadiesPaymentsExample {
    public static void main(String[] args) {
        EanPayConfig config = new EanPayConfig.Builder().mchNo(MchConfig.mchNo).mchKey(MchConfig.mchKey).build();
        EanPayCardService service = new EanPayCardService.Builder().config(config).hostname(MchConfig.hostname).build();
        CreateReadiesPaymentRequest request = new CreateReadiesPaymentRequest();
//        request.setNotifyUrl("http://localhost:8080/v1/card-pay/cybersource-payments/notify-test");
//        request.setPayerAuthRedirectUrl("http://localhost:8080/card-payer-auth/payment-result");
        request.setNotifyUrl("https://card-api.ean-pay.com/v1/card-pay/cybersource-payments/notify-test");
        request.setPayerAuthRedirectUrl("https://card-api.ean-pay.com/card-payer-auth/payment-result");
        // 订单信息
        request.setEmail("test@test.com");
        request.setAmount("5");
        request.setCurrency("EUR");
        request.setMchOrderNo(NonceUtil.createNonce(16));

        // 账单信息
//        request.setAddress1("1 Market St");
//        request.setAdministrativeArea("CA");
//        request.setCountry("US");

//        request.setFirstName("John");
//        request.setLastName("Doe");
//        request.setPostalCode("48104-2201");
//        request.setLocality("san francisco");
//        request.setPhoneNumber("85267461399");

        PaymentsPayResponse response = service.readiesPay(request);
        System.out.println(JSONObject.toJSONString(response));
    }
}
